-- Autocmds are automatically loaded on the VeryLazy event
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
--
-- Add any additional autocmds here
-- with `vim.api.nvim_create_autocmd`
-- Or remove existing autocmds by their group name (which is prefixed with `lazyvim_` for the defaults)
-- e.g. vim.api.nvim_del_augroup_by_name("lazyvim_wrap_spell")
local function augroup(name)
  return vim.api.nvim_create_augroup("lazyvim_" .. name, { clear = true })
end
vim.api.nvim_create_autocmd("FileType", {
  group = augroup("associate_filetype"),
  pattern = { "python" },
  callback = function()
    vim.opt.shiftwidth = 4
    vim.opt.formatoptions:remove({ "o" }) -- 防止使用 o 切换到下一行的时候自动加上注释符号(在上一行是注释的情况下)
  end,
})
vim.api.nvim_create_autocmd("FileType", {
  group = augroup("associate_filetype"),
  pattern = { "c", "cpp" },
  callback = function()
    vim.opt.shiftwidth = 2
    vim.opt.formatoptions:remove({ "o" }) -- 防止使用 o 切换到下一行的时候自动加上注释符号(在上一行是注释的情况下)
  end,
})
-- 在设置完高亮后，强制刷新诊断
vim.api.nvim_create_autocmd("ColorScheme", {
  pattern = "sonokai",
  callback = function()
    vim.api.nvim_set_hl(0, "VirtualTextError", { fg = "#ff5555", italic = true })
    -- 强制刷新当前 buffer 的诊断
    -- vim.schedule(function()
    --   local bufnr = vim.api.nvim_get_current_buf()
    --   local diagnostics = vim.diagnostic.get(bufnr)
    --   vim.diagnostic.reset(vim.lsp.diagnostic.get_namespace(), bufnr)
    --   vim.diagnostic.set(vim.lsp.diagnostic.get_namespace(), bufnr, diagnostics)
    -- end)
    -- vim.api.nvim_set_hl(0, "PmenuSel", {
    --    bg = "#9d7cd8",  -- 自定义紫色
    --    fg = "#ffffff",  -- 白色文字
    --    bold = true      -- 加粗
    --  })
  end,
})
-- vim.api.nvim_create_autocmd("ColorScheme", {
--   pattern = "sonokai",
--   callback = function()
--     -- Floats 透明
--     -- vim.api.nvim_set_hl(0, "NormalFloat", { bg = "NONE" })
--     -- vim.api.nvim_set_hl(0, "FloatBorder", { bg = "NONE" })
--     -- -- Sidebars 透明
--     -- vim.api.nvim_set_hl(0, "NeoTreeNormal", { bg = "NONE" })
--     -- vim.api.nvim_set_hl(0, "NvimTreeNormal", { bg = "NONE" })
--   end,
-- })

